<template>
  <div>
    <Row class="search-info-style">
      <Col span="21"></Col>
      <Col span="3">
<!--        <Button class="new-btn-sty" @click="init">-->
<!--          <Icon type="ios-search" /> 查询-->
<!--        </Button>-->
        <Button class="new-btn-sty" @click="addModal = true; message = '新增'">
          <Icon type="success" /> 新增
        </Button>
      </Col>
    </Row>
    <Row style="margin-top: 10px">
      <Table :columns="columns" :data="data">
        <template slot-scope="{ row }" slot="action">
          <!--        <Button type="primary" size="small" style="margin-right: 5px" @click="show(row)">查看</Button>-->
          <Button type="primary" size="small" style="margin-right: 5px" @click="updatePersonnel(row)">编辑</Button>
          <!--        <Button type="error" size="small" @click="remove(row)">注销</Button>-->
        </template>
      </Table>
    </Row>
    <Row v-if="loadData == true">
      <Col class="demo-spin-col" span="8" offset="8">
        <Spin fix>
          <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>
          <div>数据正在加载</div>
        </Spin>
      </Col>
    </Row>
    <Modal
      v-model="addModal" :title="message"
      @on-ok="addOk"
      ok-text="确定"
      cancel-text="取消"
      @on-cancel="addModal = false">
      <Form :model="paramData" >
        <Row class="item1">
          <Col span="7" style="text-align: right" class="">类型编号:<span style="color: red">(必填)</span></Col>
          <Col span="12" offset="1">
            <Input v-model="paramData.TYPECODE" placeholder="请输入类型编号"/>
          </Col>
        </Row>
        <Row class="item1">
          <Col span="7" style="text-align: right" class="">类型名称:<span style="color: red">(必填)</span></Col>
          <Col span="12" offset="1">
            <Input v-model="paramData.TYPENAME" placeholder="请输入类型名称"/>
          </Col>
        </Row>
      </Form>
    </Modal>
  </div>
</template>
<script>
import { findPersonnelTypeList, addPersonnelType } from '@/api/eventlist'
export default {
  data () {
    return {
      addModal: false,
      loadData: true,
      message: '新增',
      paramData: {},
      data: [],
      columns: [
        { type: 'index', width: 50, align: 'center' },
        { title: '类型编号', key: 'TYPECODE', minWidth: 90, align: 'center' },
        { title: '类型名称', key: 'TYPENAME', minWidth: 90, align: 'center' },
        { title: '操作', slot: 'action', minWidth: 90, align: 'center'}
      ]
    }
  },
  methods: {
    init() {
      findPersonnelTypeList().then(res => {
        if (res.data.errcode === 0) {
          this.data = res.data.data
          this.loadData = false
        } else {
          this.$Notice.error({ title: '获取列表失败', desc: '' })
        }
      })
    },
    addOk () {
      addPersonnelType(this.paramData).then(res => {
        if (res.data.errcode === 0) {
          this.loadData = true
          this.init()
        } else {
          this.$Notice.error({ title: '操作失败', desc: '' })
        }
      })
    },
    updatePersonnel (item) {
      this.message = '编辑'
      this.paramData = this.$common.xeUtils.clone(item,true)
      this.addModal = true
    }
  },
  mounted() {
    this.init()
  }
}
</script>
<style>
.item1{
  height: 42px;
  line-height: 40px;
}
.card_style {
  height: 100%;
  width: 100%;
  overflow: hidden;
.ivu-card-body {
  padding: 0px;
}
}
.page_style {
  margin-top: 10px;
  text-align: right;
}
.bench_search {
  margin-bottom: 10px;
}
.nopadding .ivu-table-cell {
  padding: 0px 0px;
}
.item1{
  height: 42px;
  line-height: 40px;
}
.marginR2 {
  margin-right: 2%;
}
.fontsize20 {
  font-size: 20px;
}
.fontTitle {
  font-size: 20px;
  height: 52px;
  text-align: right;
  padding-top: 16px;
}
.fontContent {
  font-size: 20px;
  height: 52px;
  text-align: left;
  padding-top: 16px;
  color: #dc9387;
}
.countNum {
  font-size: 35px;
  color: #dc9387;
}
.new-btn-sty {
  margin-right: 5px;
  color: #fff;
  background-color: #235CA7;
  border-color: #235CA7;
  font-weight: 500;
}
.new-btn-sty1 {
  margin-right: 5px;
  color: #fff;
  background-color: #598ED1;
  border-color: #598ED1;
  font-weight: 500;
}
.text-overflow{
  width:300px; /* 超过宽度就显示... */
  text-overflow: ellipsis; /* 显示... */
  overflow: hidden; /* 隐藏文字 */
  white-space: nowrap; /* 不换行 */
  cursor: pointer; /* hover显示手形 */
}
.search-info-style{
  margin-top: 10px;
}
.table-input{
  border: #312e2e solid 1px;
  border-left: 0px;
  border-right: 0px;
  line-height: 50px;
}
.table-col{
  border: #312e2e solid 1px;
  line-height: 50px;
}
</style>
